package com.ruoyi.system.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.AdvertisementInfo;
import com.ruoyi.system.service.IAdvertisementInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 广告信息Controller
 * 
 * @author ruoyi
 * @date 2021-04-07
 */
@RestController
@RequestMapping("/system/advertisementinfo")
public class AdvertisementInfoController extends BaseController
{
    @Autowired
    private IAdvertisementInfoService advertisementInfoService;

    /**
     * 查询广告信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:advertisementinfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(AdvertisementInfo advertisementInfo)
    {
        List<AdvertisementInfo> list = advertisementInfoService.selectAdvertisementInfoList(advertisementInfo);
        return getDataTable(list);
    }

    /**
     * 导出广告信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:advertisementinfo:export')")
    @Log(title = "广告信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(AdvertisementInfo advertisementInfo)
    {
        List<AdvertisementInfo> list = advertisementInfoService.selectAdvertisementInfoList(advertisementInfo);
        ExcelUtil<AdvertisementInfo> util = new ExcelUtil<AdvertisementInfo>(AdvertisementInfo.class);
        return util.exportExcel(list, "advertisementinfo");
    }

    /**
     * 获取广告信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:advertisementinfo:query')")
    @GetMapping(value = "/{advertisementId}")
    public AjaxResult getInfo(@PathVariable("advertisementId") String advertisementId)
    {
        return AjaxResult.success(advertisementInfoService.selectAdvertisementInfoById(advertisementId));
    }

    /**
     * 新增广告信息
     */
    @PreAuthorize("@ss.hasPermi('system:advertisementinfo:add')")
    @Log(title = "广告信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AdvertisementInfo advertisementInfo)
    {
        return toAjax(advertisementInfoService.insertAdvertisementInfo(advertisementInfo));
    }

    /**
     * 修改广告信息
     */
    @PreAuthorize("@ss.hasPermi('system:advertisementinfo:edit')")
    @Log(title = "广告信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AdvertisementInfo advertisementInfo)
    {
        return toAjax(advertisementInfoService.updateAdvertisementInfo(advertisementInfo));
    }

    /**
     * 删除广告信息
     */
    @PreAuthorize("@ss.hasPermi('system:advertisementinfo:remove')")
    @Log(title = "广告信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{advertisementIds}")
    public AjaxResult remove(@PathVariable String[] advertisementIds)
    {
        return toAjax(advertisementInfoService.deleteAdvertisementInfoByIds(advertisementIds));
    }
}
